﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GestionPedago.Services.ES.Modele;
using GestionPedago.Services.ES;
using GestionPedago.Services;
using System.Collections.ObjectModel;

namespace GestionPedago.ViewModel
{
    /// <summary>
    /// Interaction logic for ListViewEvenementsUC.xaml
    /// </summary>
    public partial class ListViewEvenementsUC : UserControl
    {

        /// <summary>
        /// Constructeur de la classe ListViewEvenementsUC
        /// </summary>
        public ListViewEvenementsUC()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Double clique sur un élément de la liste.
        /// </summary>
        private void ListViewEvents_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            EvenementPedagogiqueES evenement = ListViewEvents.SelectedItem as EvenementPedagogiqueES;
            OpenEvenementsPedagogiques(evenement);
        }


        /// <summary>
        /// 
        /// </summary>
        private void OpenEvenementsPedagogiques(EvenementPedagogiqueES evenement)
        {
            if (evenement != null)
            {
                MainWindowVM parentVM = null;

                if (this.DataContext is CartoucheStagiaireVM)
                {
                    parentVM = ((CartoucheStagiaireVM)this.DataContext).vmMainWindow;
                }
                else if (this.DataContext is EvenementsPedagogiquesVM)
                {
                    parentVM = ((EvenementsPedagogiquesVM)this.DataContext).Parent.vmMainWindow;
                    UpdateStagiaire(evenement.Stagiaire);
                }
                CreaModEvenementPedagogiqueVM vmCreaModEvenementPedagogique = new CreaModEvenementPedagogiqueVM(parentVM.vmGestionnaireOnglets);
                parentVM.vmGestionnaireOnglets.Onglets.Add(vmCreaModEvenementPedagogique);
                parentVM.vmGestionnaireOnglets.SelectedOnglet = vmCreaModEvenementPedagogique;
                vmCreaModEvenementPedagogique.CurrentEvenement = evenement;
            }
        }

        private void UpdateStagiaire(StagiaireES stagiaire)
        {
            ((EvenementsPedagogiquesVM)this.DataContext).Parent.vmMainWindow.CurrentStagiaire = stagiaire;
            RechercherListeEvtPedagogiquesIn paramEntree = new RechercherListeEvtPedagogiquesIn();
            paramEntree.CodeStagiaire = stagiaire.CodeStagiaire;
            ((EvenementsPedagogiquesVM)this.DataContext).Parent.vmMainWindow.vmCartoucheStagiaire.ListeEvenementsPedagogique = new ObservableCollection<EvenementPedagogiqueES>(FacadeServices.GetInstance().RechercherListeEvtPedagogiques(paramEntree).ListeEvenements);
        }
    }
}
